Read in water year data from CSVs in the
intermediate_data directory
#read in necessary CSV files from prior RMDs
all_streamflow <- read_csv(here("intermediate_data", "all_streamflow.csv"))
air_temp_30_clean <- read_csv(here("intermediate_data", "air_temp_30_clean.csv"))
mc_clean <- read_csv(here("intermediate_data", "mc_clean.csv")) %>%
rename(datetime = collected)
precip_15_clean <- read_csv(here("intermediate_data", "precip_15_clean.csv"))
precip_6h_clean <- read_csv(here("intermediate_data", "precip_6h_clean.csv"))
precip_12h_clean <- read_csv(here("intermediate_data", "precip_12h_clean.csv"))
precip_daily_clean <- read_csv(here("intermediate_data", "precip_daily_clean.csv"))
precip_daily_join <- read_csv(here("intermediate_data", "precip_daily_join.csv"))
Set constant values
#set constants
min_year = 2017
max_year = 2021
Create sub-directories if necessary
output_dir <- file.path(here("intermediate_data"))
if (!dir.exists(output_dir)){
dir.create(output_dir)
} else {
print("Directory already exists!")
}
## [1] "Directory already exists!"
output_dir <- file.path(here("figures"))
if (!dir.exists(output_dir)){
dir.create(output_dir)
} else {
print("Directory already exists!")
}
## [1] "Directory already exists!"
For interactive plots, cumulative precipitation is plotted as grey bars, and air temperature is plotted as a red line.
#format precipitation data for plotting
precip_15_join <- precip_15_clean %>%
pivot_wider(
names_from = "precip_type",
values_from = "precip_in"
) %>%
subset(year >= min_year & year <= max_year)
#format air temperature data for plotting
airtemp_join <- air_temp_30_clean %>%
pivot_wider(
names_from = "airtemp_type",
values_from = "airtempC"
) %>%
subset(year >= min_year & year <= max_year) %>%
mutate(freezing = as.factor(freezing))
#format air temp data for plotting
precip_air <- full_join(x = precip_15_join,
y = airtemp_join,
by = c("datetime", "year")) %>%
subset(year >= min_year & year <= max_year)
#plot
p_15 <- ggplot() +
#airtemp data
geom_line(data = airtemp_join,
aes(x = datetime,
y = airtempc_100),
color = "pink",
alpha = 0.5,
size = 0.25) +
#precipitation data
geom_line(data = precip_15_join,
aes(x = datetime,
y = precip_10,
colour = I("grey")),
size = 0.25) +
theme_classic() +
labs(x = "Time",
title = "S2 Precipitation Every 15min and Air Temperature Every 30min",
subtitle = "Cumulative precipitation is plotted in grey. \n Air temperature is plotted in pink.") +
theme(plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5,
size = 7)) +
scale_y_continuous(
# Features of the first axis
name = "Air Temperature (ÂșC) / 100",
# Add a second axis and specify its features
sec.axis = sec_axis(trans = ~., name = "Cumulative Precipitation (in) / 10")
)
#static plot
#p_15
#save figure
ggsave(filename = "precip_15_airtemp_30.png",
plot = p_15,
path = "figures/",
width = 10,
height = 5,
units = c("in"),
dpi = 300)
#interactive plot
ggplotly(p_15)